import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xingsu/page/home/home_page.dart';
import 'package:xingsu/page/publisher/publisher_page.dart';
import 'package:xingsu/page/mine/mine_page.dart';
import 'package:xingsu/page/tab/tab_viewmodel.dart';
import 'package:xingsu/page/team/team_page.dart';
import 'package:xingsu/res/colors.dart';
import 'package:xingsu/res/theme.dart';
import 'package:xingsu/util/image_util.dart';

class TabPage extends StatelessWidget {
  final TabViewModel _viewModel = Get.put(TabViewModel());

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          body: PageView(
            controller: _viewModel.controller,
            physics: const NeverScrollableScrollPhysics(),
            children: const [
              HomePage(),
              PublisherPage(),
              // TeamPage(),
              MinePage(),
            ],
          ),
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: _viewModel.currentIndex.value,
            selectedFontSize: 10,
            unselectedFontSize: 10,
            backgroundColor: context.backgroundColor,
            type: BottomNavigationBarType.fixed,
            selectedItemColor: Colours.app_main,
            unselectedItemColor: Colours.grayColor,
            onTap: (index) {
              _viewModel.controller.jumpToPage(index);
              _viewModel.currentIndex.value = index;
            },
            items: _viewModel.tabs
                .map((tab) => BottomNavigationBarItem(
                      label: tab.first,
                      icon: loadAssetImage(tab.last,
                          width: 24,
                          color: _viewModel.currentIndex.value ==
                                  _viewModel.tabs.indexOf(tab)
                              ? Colours.app_main
                              : Colours.grayColor),
                    ))
                .toList(),
          ),
        ));
  }
}
